<cfparam name="action" type="string" default="">
<cfif action eq "debug">
	<h1>ARGS</h1>
	<p>ARGS collection will set to the first of FORM, URL or REQUEST scopes that has an ACTION parameter.</p>
	<p>For this submission, ARGS set from...</p>
	<cfif StructKeyExists(form, "action")>
		<h2>FORM</h2>
		<cfdump var="#form#" label="ARGS" expand="no">
	<cfelseif StructKeyExists(url, "action")>
		<h2>URL</h2>
		<cfdump var="#url#" label="ARGS" expand="no">
	<cfelseif StructKeyExists(request, "action")>
		<h2>REQUEST</h2>
		<cfdump var="#request#" label="ARGS" expand="no">
	<cfelse>
		<h2>ACTION not found</h2>
		<p>ACTION parameter not found in scopes.  ARGS set to empty struct.</p>
		<cfdump var="#StructNew()#" label="New empty struct" expand="yes">
	</cfif>
	<cfabort>
</cfif>
<cfscript>
	if (IsDefined("form.action")) {
		args = Duplicate(form);
	} else if (IsDefined("url.action")) {
		args = Duplicate(url);
	} else if (IsDefined("request.action")) {
		args = StructCopy(request);
	} else {
		args = StructNew();
	};
	if (StructCount(args) gt 0) {
		base = new assets.calgrants.com.Base();
		switch(args.action) {
			case "saveFollowUpsImport":
				studentGateway = new assets.calgrants.com.gateway.StudentGateway();
				for (i=1; i lte ListLen(args.Student_ID); i=i+1) {
					studentID = ListGetAt(args.Student_ID, i);
					student = studentGateway.get(Student_ID = studentID);
					student.setFollow_Up_Status(args["Follow_Up_Status_#studentID#"]);
					student.setFollow_Up_FAFSA(args["Follow_Up_FAFSA_#studentID#"]);
					student.setFollow_Up_CA_Dream_Act(args["Follow_Up_CA_Dream_Act_#studentID#"]);
					student.setFollow_Up_Taxes(args["Follow_Up_Taxes_#studentID#"]);
					student.setFollow_Up_Income_Assets(args["Follow_Up_Income_Assets_#studentID#"]);
					student.setFollow_Up_Cal_Grant_Deadline(args["Follow_Up_Cal_Grant_Deadline_#studentID#"]);
					student.setFollow_Up_Cal_Grant_Requirements(args["Follow_Up_Cal_Grant_Requirements_#studentID#"]);
					student.setFollow_Up_Other(args["Follow_Up_Other_#studentID#"]);
					student.setFollow_Up_Notes(args["Follow_Up_Notes_#studentID#"]);
					studentGateway.save(student);
				}			
			break;
			case "import":
				if (StructKeyExists(args, "fileField") and StructKeyExists(args, args.fileField) and StructKeyExists(args, "collection")) {
					upload = base.uploadFormFile(argumentCollection = args);
					if (upload.fileWasSaved) {
						uploadFile = upload.ServerDirectory & "\" & upload.ServerFile;
						switch(args.collection) {
							case "followUps":
								if (upload.serverFileExt neq "xls" and upload.serverFileExt neq "xlsx") {
									error = "Selected file is not an Excel spreadsheet";
									view = "error";
									fileDelete(uploadFile);
								}									
							break;
							case "volunteers":
								if (upload.serverFileExt neq "xls" and upload.serverFileExt neq "xlsx") {
									error = "Selected file is not an Excel spreadsheet";
									view = "error";
									fileDelete(uploadFile);
								}									
							break;
							case "processedPayments":
								if (upload.serverFileExt neq "xls" and upload.serverFileExt neq "xlsx") {
									error = "Selected file is not an Excel spreadsheet";
									view = "error";
									fileDelete(uploadFile);
								}								
							break;
						};
					} else {
						error = "Upload failed";
						view = "error";
					};
				} else {
					error = "Required value(s) missing from submission";
					view = "error";
				};
			break;
			case "export":
				// default export format to csv, override in switch case for Excel (use "xls")
				exportFormat = "csv";
				switch(args.collection) {
					case "funds":
						fundGateway = new assets.calgrants.com.gateway.FundGateway();
						data = fundGateway.query(argumentCollection = base.wddxToCFML(client.funds.queryParamsWDDX));
						cols = "FUND_ID,
								PROGRAM_YEAR,
								APPROVED,
								DELETED,
								ORGANIZATION_ID,
								REQUESTED_BY_ID,
								APPROVED_BY_ID,
								APPROVED_DATE,
								FUND_WORKSHOP_COUNT,
								FUND_AMOUNT_TOTAL,
								PAYEE_FIRST_NAME,
								PAYEE_LAST_NAME,
								PAYEE_ORGANIZATION,
								PAYEE_DEPARTMENT,
								PAYEE_ADDRESS,
								PAYEE_CITY,
								PAYEE_STATE,
								PAYEE_ZIP_CODE,
								PAYEE_PHONE,
								PAYEE_EMAIL,
								PAYEE_TAX_ID,
								SIGNATURE,
								DATE_CREATED,
								ORGANIZATION_APPROVED,
								ORGANIZATION_DELETED,
								ORGANIZATION_ARCHIVED,
								ORGANIZATION,
								REQUESTED_BY_FIRST_NAME,
								REQUESTED_BY_LAST_NAME,
								REQUESTED_BY_PHONE,
								REQUESTED_BY_EXTENSION,
								REQUESTED_BY_EMAIL,
								APPROVED_BY_FIRST_NAME,
								APPROVED_BY_LAST_NAME,
								APPROVED_BY_PHONE,
								APPROVED_BY_EXTENSION,
								APPROVED_BY_EMAIL,
								COUNTY,
								REGION_ID,
								REGION,
								QUERY_DATE";
					break;
					case "orders":
						orderGateway = new assets.calgrants.com.gateway.OrderGateway();
						data = orderGateway.query(argumentCollection = base.wddxToCFML(client.orders.queryParamsWDDX));
						cols = "ORDER_ID,					
								PROGRAM_YEAR,	
								APPROVED,
								DELETED,
								DATE_CREATED,
								NEXT_WORKSHOP_DATE,
								ANTICIPATED_SHIP_DATE,		
								FULFILLMENT_DATE,
								STUDENT_COUNT,
								VOLUNTEER_COUNT,
								SHIPPING_ORGANIZATION,
								SHIPPING_DEPARTMENT,
								SHIPPING_NAME,
								SHIPPING_ADDRESS,
								SHIPPING_CITY,
								SHIPPING_STATE,
								SHIPPING_ZIP_CODE,
								SHIPPING_PHONE,
								SHIPPING_INSTRUCTIONS,
								ORDERED_BY_ID,
								ORDERED_BY_APPROVED,
								ORDERED_BY_ARCHIVED,
								ORDERED_BY_DELETED,
								ORDERED_BY_FULL_NAME,
								ORGANIZATION_ID,
								ORGANIZATION_APPROVED,
								ORGANIZATION_ARCHIVED,
								ORGANIZATION_DELETED,
								ORGANIZATION,
								COUNTY,
								REGION,
								REGION_ID,
								QUERY_DATE";
					break;
					case "workshops":
						workshopGateway = new assets.calgrants.com.gateway.WorkshopGateway();
						data = workshopGateway.query(argumentCollection = base.wddxToCFML(client.workshops.queryParamsWDDX));
						cols = "WORKSHOP_ID,
								PROGRAM_YEAR,
								APPROVED,
								DELETED,
								EVALUATION_CODE,
								WORKSHOP_DATE,
								START_TIME,
								END_TIME,
								ANTICIPATED_COMPUTERS,
								ANTICIPATED_STUDENTS,
								ANTICIPATED_VOLUNTEERS,
								STUDENT_COUNT,
								STUDENT_COUNT_WEB,
								STUDENT_COUNT_PB,
								FOLLOW_UP_REQUEST_COUNT,
								ORGANIZATION_ID,
								ORGANIZATION_APPROVED,
								ORGANIZATION_ARCHIVED,
								ORGANIZATION_DELETED,
								ORGANIZATION,
								SITE_ID,
								SITE,
								ADDRESS,
								CITY,
								ZIP_CODE,
								COUNTY,
								REGION,
								REGION_ID,
								ORGANIZER_ID,
								ORGANIZER_APPROVED,
								ORGANIZER_ARCHIVED,
								ORGANIZER_DELETED,
								ORGANIZER_FULL_NAME,
								ORGANIZER_FIRST_NAME,
								ORGANIZER_LAST_NAME,
								ORGANIZER_EMAIL,
								ORGANIZER_PHONE,
								ORGANIZER_EXTENSION,
								MANAGER_ID,
								MANAGER_APPROVED,
								MANAGER_ARCHIVED,
								MANAGER_DELETED,
								MANAGER_FULL_NAME,
								MANAGER_EMAIL,
								MANAGER_PHONE,
								MANAGER_EXTENSION,
								ONLINE,
								OFFLINE_REASONS,
								FAFSA_ON_THE_WEB,
								FINANCIAL_AID_PRESENTATION,
								AB540,
								SEPARATE_AREAS,
								SMALL_GROUP,
								FOSTER_YOUTH,
								ALT_LANGUAGES,
								ALT_LANGUAGE_WORKSHOP,
								TAX_ASSISTANCE,
								TRANSLATORS,
								TRANSLATOR_LANGUAGES,
								CHILD_CARE,
								REFRESHMENTS,
								OTHER_SERVICES,
								OTHER_SERVICES_DESCRIPTION,
								PB_NOTES,
								PB_SHIPPED_DATE,
								PB_SURVEY_COUNT,
								PB_SURVEY_COUNT_STATUS,
								DATE_CREATED,
								QUERY_DATE";
					break;
					case "organizations":
						organizationGateway = new assets.calgrants.com.gateway.OrganizationGateway();
						data = organizationGateway.query(argumentCollection = base.wddxToCFML(client.organizations.queryParamsWDDX));
						cols = "ORGANIZATION_ID,
								APPROVED,
								ARCHIVED,
								DELETED,
								ORGANIZATION,
								ADDRESS,
								CITY,
								ZIP_CODE,
								COUNTY,
								COUNTY_ID,
								REGION,
								REGION_ID,
								PROGRAM_YEAR,
								PROGRAM_YEARS,
								INITIAL_PROGRAM_YEAR,
								PA,
								OAP,
								USER_COUNT,
								WORKSHOP_COUNT,
								ORDER_COUNT,
								STUDENT_COUNT,
								DATE_CREATED,
								QUERY_DATE";
					break;
					case "users":
						userGateway = new assets.calgrants.com.gateway.UserGateway();
						data = userGateway.query(argumentCollection = base.wddxToCFML(client.users.queryParamsWDDX));
						cols = "USER_ID,					
								APPROVED,
								ARCHIVED,
								DELETED,
								FIRST_NAME,
								LAST_NAME,
								FULL_NAME,
								TITLE,
								ROLE,
								REGION_IDS,
								PHONE,
								EXTENSION,
								EMAIL,
								WORKSHOP_COUNT,
								ORDER_COUNT,
								ORGANIZATION_ID,
								ORGANIZATION,
								ORGANIZATION_APPROVED,
								ORGANIZATION_ARCHIVED,
								ORGANIZATION_DELETED,
								COUNTY,
								REGION,
								REGION_ID,
								DATE_CREATED,
								QUERY_DATE";
					break;
					case "followUps": case "allFollowUps":
						// override exportFomat from csv to xls
						exportFormat = "xls";
						studentGateway = new assets.calgrants.com.gateway.StudentGateway();
						if (args.collection eq "followUps") {
							if (IsUserInRole("Super User") or IsUserInRole("Regional Admin")) {
								clientStudentsParams = base.wddxToCFML(client.students.queryParamsWDDX);
								clientStudentsParams.followUp = 1;
								followUps = studentGateway.query(argumentCollection = clientStudentsParams);
							} else {
								followUps = studentGateway.query(Workshop_ID = args.Workshop_ID, followUp = 1);
							}
						} else if (args.collection eq "allFollowUps") {
							if (IsUserInRole("Super User") or IsUserInRole("Regional Admin")) {
								followUps = studentGateway.query(regionIDs = IIf(IsUserInRole("Regional Admin"), request.authUser.regionID, ""), programYear = request.currentProgramYear, followUp = 1);
							} else {
								followUps = studentGateway.query(organizationIDs = request.authUser.organizationID, programYear = request.currentProgramYear, followUp = 1);
							}
						};
						cols = "STUDENT_ID,
								SITE,
								WORKSHOP_DATE,
								REGION_ID,
								FOLLOW_UP_STATUS,
								FOLLOW_UP_FAFSA,
								FOLLOW_UP_CA_DREAM_ACT,
								FOLLOW_UP_TAXES,
								FOLLOW_UP_INCOME_ASSETS,
								FOLLOW_UP_CAL_GRANT_DEADLINE,
								FOLLOW_UP_CAL_GRANT_REQUIREMENTS,
								FOLLOW_UP_OTHER,
								FOLLOW_UP_NOTES,
								FIRST_NAME,
								LAST_NAME,
								ADDRESS,
								CITY,
								ZIP_CODE,
								PHONE1,
								PHONE2,
								EMAIL,
								HAVE_SSN,
								ALT_CONTACT_FIRST_NAME,
								ALT_CONTACT_LAST_NAME,
								ALT_CONTACT_ADDRESS,
								ALT_CONTACT_CITY,
								ALT_CONTACT_ZIP_CODE,
								ALT_CONTACT_PHONE,
								ALT_CONTACT_EMAIL,
								HIGH_SCHOOL_SENIOR,
								HIGH_SCHOOL,
								RACE_ETHNICITY,
								FIRST_GENERATION,
								FINISH_FAFSA,
								WHY_DID_NOT_FINISH_FAFSA,
								WANT_HELP,
								EXPORT_DATE_TIME";
						data = QueryNew(cols);
						for (i = 1; i lte followUps.RecordCount; i = i + 1) {
							QueryAddRow(data);
							data["Student_ID"][i] = followUps["Student_ID"][i];
							data["Site"][i] = followUps["Site"][i];
							data["Workshop_Date"][i] = DateFormat(followUps["Workshop_Date"][i], "m/d/yyyy") & " " & TimeFormat(followUps["Start_Time"][i], "h:mmtt") & "-" & TimeFormat(followUps["End_Time"][i], "h:mmtt");
							data["Region_ID"][i] = followUps["Region_ID"][i];
							if (Len(Trim(followUps["Follow_Up_Status"][i])) gt 0) {
								data["Follow_Up_Status"][i] = followUps["Follow_Up_Status"][i];
							} else {
								data["Follow_Up_Status"][i] = "Not Complete";
							};
							data["Follow_Up_FAFSA"][i] = IIf(IsBoolean(followUps["Follow_Up_FAFSA"][i]), DE(YesNoFormat(followUps["Follow_Up_FAFSA"][i])), "");
							data["Follow_Up_CA_Dream_Act"][i] = IIf(IsBoolean(followUps["Follow_Up_CA_Dream_Act"][i]), DE(YesNoFormat(followUps["Follow_Up_CA_Dream_Act"][i])), "");
							data["Follow_Up_Taxes"][i] = IIf(IsBoolean(followUps["Follow_Up_Taxes"][i]), DE(YesNoFormat(followUps["Follow_Up_Taxes"][i])), "");
							data["Follow_Up_Income_Assets"][i] = IIf(IsBoolean(followUps["Follow_Up_Income_Assets"][i]), DE(YesNoFormat(followUps["Follow_Up_Income_Assets"][i])), "");
							data["Follow_Up_Cal_Grant_Deadline"][i] = IIf(IsBoolean(followUps["Follow_Up_Cal_Grant_Deadline"][i]), DE(YesNoFormat(followUps["Follow_Up_Cal_Grant_Deadline"][i])), "");
							data["Follow_Up_Cal_Grant_Requirements"][i] = IIf(IsBoolean(followUps["Follow_Up_Cal_Grant_Requirements"][i]), DE(YesNoFormat(followUps["Follow_Up_Cal_Grant_Requirements"][i])), "");
							data["Follow_Up_Other"][i] = followUps["Follow_Up_Other"][i];
							data["Follow_Up_Notes"][i] = followUps["Follow_Up_Notes"][i];
							data["First_Name"][i] = followUps["First_Name"][i];
							data["Last_Name"][i] = followUps["Last_Name"][i];
							data["Address"][i] = followUps["Address"][i];
							data["City"][i] = followUps["City"][i];
							data["Zip_Code"][i] = followUps["Zip_Code"][i];
							data["Phone1"][i] = followUps["Phone1"][i];
							data["Phone2"][i] = followUps["Phone2"][i];
							data["Email"][i] = followUps["Email"][i];
							if (followUps["SSN_Code"][i] eq 1) {
								data["Have_SSN"][i] = "I have an SSN";
							} else if (followUps["SSN_Code"][i] eq 2) {
								data["Have_SSN"][i] = "I do not have an SSN";
							} else if (followUps["SSN_Code"][i] eq 3) {
								data["Have_SSN"][i] = "I don't remember my SSN";
							};
							data["Alt_Contact_First_Name"][i] = followUps["First_Name_Alt1"][i];
							data["Alt_Contact_Last_Name"][i] = followUps["Last_Name_Alt1"][i];
							data["Alt_Contact_Address"][i] = followUps["Address_Alt1"][i];
							data["Alt_Contact_City"][i] = followUps["City_Alt1"][i];
							data["Alt_Contact_Zip_Code"][i] = followUps["Zip_Code_Alt1"][i];
							data["Alt_Contact_Phone"][i] = followUps["Phone_Alt1"][i];
							data["Alt_Contact_Email"][i] = followUps["Email_Alt1"][i];
							if (followUps["Q5"][i] eq 1) {
								data["First_Generation"][i] = "Yes";
							} else if (followUps["Q5"][i] eq 2) {
								data["First_Generation"][i] = "No";
							};
							if (followUps["Q7"][i] eq 1) {
								data["High_School_Senior"][i] = "Yes";
							} else if (followUps["Q7"][i] eq 2) {
								data["High_School_Senior"][i] = "No";
							} else if (followUps["Q7"][i] eq 3) {
								data["High_School_Senior"][i] = "Family member of a senior";
							};
							data["High_School"][i] = followUps["Q8"][i];
							if (ListFind(followUps["Q12"][i], 1)) {
								data["Race_Ethnicity"][i] = ListAppend(data["Race_Ethnicity"][i], "American Indian or Alaskan Native", ";");
							};
							if (ListFind(followUps["Q12"][i], 2)) {
								data["Race_Ethnicity"][i] = ListAppend(data["Race_Ethnicity"][i], "Asian", ";");
							};
							if (ListFind(followUps["Q12"][i], 3)) {
								data["Race_Ethnicity"][i] = ListAppend(data["Race_Ethnicity"][i], "Black/African American", ";");
							};
							if (ListFind(followUps["Q12"][i], 4)) {
								data["Race_Ethnicity"][i] = ListAppend(data["Race_Ethnicity"][i], "Hispanic/Latino", ";");
							};
							if (ListFind(followUps["Q12"][i], 5)) {
								data["Race_Ethnicity"][i] = ListAppend(data["Race_Ethnicity"][i], "Native Hawaiian or other Pacific Islander", ";");
							};
							if (ListFind(followUps["Q12"][i], 6)) {
								data["Race_Ethnicity"][i] = ListAppend(data["Race_Ethnicity"][i], "White", ";");
							};
							if (ListFind(followUps["Q12"][i], 7)) {
								data["Race_Ethnicity"][i] = ListAppend(data["Race_Ethnicity"][i], ReplaceNoCase(followUps["Q12_Other"][i], ",", "", "all"), ";");
							};
							if (ListFind(followUps["Q12"][i], 8)) {
								data["Race_Ethnicity"][i] = ListAppend(data["Race_Ethnicity"][i], "Decline to answer", ";");
							};
							if (Len(Trim(followUps["Q12"][i])) eq 0) {
								data["Race_Ethnicity"][i] = ListAppend(data["Race_Ethnicity"][i], "Did not answer", ";");
							};
							if (followUps["Q15"][i] eq 1) {
								data["Finish_FAFSA"][i] = "Yes";
							} else if (followUps["Q15"][i] eq 2) {
								data["Finish_FAFSA"][i] = "Some not all";
							} else if (followUps["Q15"][i] eq 3) {
								data["Finish_FAFSA"][i] = "No";
							};
							if (ListFind(followUps["Q16"][i], 1)) {
								data["Why_Did_Not_Finish_FAFSA"][i] = ListAppend(data["Why_Did_Not_Finish_FAFSA"][i], "Thought I had to have taxes completed", ";");
							};
							if (ListFind(followUps["Q16"][i], 2)) {
								data["Why_Did_Not_Finish_FAFSA"][i] = ListAppend(data["Why_Did_Not_Finish_FAFSA"][i], "Didn't bring enough financial info with me", ";");
							};
							if (ListFind(followUps["Q16"][i], 3)) {
								data["Why_Did_Not_Finish_FAFSA"][i] = ListAppend(data["Why_Did_Not_Finish_FAFSA"][i], "Technical problem with computer", ";");
							};
							if (ListFind(followUps["Q16"][i], 4)) {
								data["Why_Did_Not_Finish_FAFSA"][i] = ListAppend(data["Why_Did_Not_Finish_FAFSA"][i], "Will submit later on the Internet", ";");
							};
							if (ListFind(followUps["Q16"][i], 5)) {
								data["Why_Did_Not_Finish_FAFSA"][i] = ListAppend(data["Why_Did_Not_Finish_FAFSA"][i], "Asked for AB 540 help", ";");
							};
							if (ListFind(followUps["Q16"][i], 6)) {
								data["Why_Did_Not_Finish_FAFSA"][i] = ListAppend(data["Why_Did_Not_Finish_FAFSA"][i], ReplaceNoCase(followUps["Q16_Other"][i], ",", "", "all"), ";");
							};
							if (Len(Trim(followUps["Q16"][i])) eq 0) {
								data["Why_Did_Not_Finish_FAFSA"][i] = ListAppend(data["Why_Did_Not_Finish_FAFSA"][i], "Did not answer", ";");
							};
							if (followUps["Q17"][i] eq 1) {
								data["Want_Help"][i] = "Yes";
							} else if (followUps["Q17"][i] eq 2) {
								data["Want_Help"][i] = "Maybe";
							} else if (followUps["Q17"][i] eq 3) {
								data["Want_Help"][i] = "No";
							};
							data["Export_Date_Time"][i] = followUps["Query_Date"][i];			
						};
					break;
					case "students": case "allStudents":
						studentGateway = new assets.calgrants.com.gateway.StudentGateway();
						if (args.collection eq "students") {
							data = studentGateway.query(argumentCollection = base.wddxToCFML(client.students.queryParamsWDDX));
						} else if (args.collection eq "allStudents") {
							clientStudentsParams = base.wddxToCFML(client.students.queryParamsWDDX);
							if (!StructKeyExists(clientStudentsParams, "programYear") or Len(Trim(clientStudentsParams.programYear)) eq 0) {
								py = request.currentProgramYear;
							} else {
								py = clientStudentsParams.programYear;
							};
							data = studentGateway.query(programYear = py);
						};
						cols = data.columnList;
						/*cols = "STUDENT_ID,
								ORIGIN,
								FOLLOW_UP_STATUS,
								FOLLOW_UP_FAFSA,
								FOLLOW_UP_CA_DREAM_ACT,
								FOLLOW_UP_TAXES,
								FOLLOW_UP_INCOME_ASSETS,
								FOLLOW_UP_CAL_GRANT_DEADLINE,
								FOLLOW_UP_CAL_GRANT_REQUIREMENTS,
								FOLLOW_UP_OTHER,
								FOLLOW_UP_NOTES,
								FIRST_NAME,
								LAST_NAME,
								ADDRESS,
								CITY,
								ZIP_CODE,
								PHONE1,
								PHONE2,
								EMAIL,
								DOB,
								SSN_CODE,
								SSN,
								FIRST_NAME_ALT1,
								LAST_NAME_ALT1,
								ADDRESS_ALT1,
								CITY_ALT1,
								ZIP_CODE_ALT1,
								PHONE_ALT1,
								EMAIL_ALT1,
								EVALUATION_ID,
								Q1,
								Q2,
								Q3,
								Q4,
								Q5,
								Q6,
								Q7,
								Q8,
								Q9,
								Q9_OTHER,
								Q10,
								Q11,
								Q12,
								Q12_OTHER,
								Q13,
								Q13_OTHER,
								Q14,
								Q14_OTHER,
								Q15,
								Q16,
								Q16_OTHER,
								Q17,
								Q18,
								Q18_OTHER,
								Q19,
								ORGANIZATION_ID,
								ORGANIZATION,
								ORGANIZATION_ADDRESS,
								ORGANIZATION_CITY,
								ORGANIZATION_ZIP_CODE,
								WORKSHOP_ID,
								WORKSHOP_DATE,
								START_TIME,
								END_TIME,
								SITE_ID,
								SITE,
								SITE_TYPE,
								SITE_ADDRESS,
								SITE_CITY,
								SITE_ZIP_CODE,
								COUNTY_ID,
								COUNTY,
								REGION_ID,
								REGION,
								QUERY_DATE";*/
					break;
					case "evaluations":
						//workshopIDs = "All";
						if (StructKeyExists(args, "workshopIDs")) {
							workshopsIDs = args.workshopIDs;
							evaluationGateway = new assets.calgrants.com.gateway.EvaluationGateway();
							data = evaluationGateway.query(organizationIDs = IIf(IsUserInRole("Organizer") OR IsUserInRole("Site Contact"), request.authUser.organizationID, ""), workshopIDs = IIf(ListFind(workshopIDs, "All") eq 0 AND Len(Trim(workshopIDs)) gt 0, DE(workshopIDs), ""), managerIDs = IIf(IsUserInRole("Site Contact"), request.authUser.userID, ""), programYears = request.currentProgramYear);
							//cols = "#data.columnlist#";	
							cols = "STUDENT_ID,
								ORIGIN,
								FOLLOW_UP_STATUS,
								FOLLOW_UP_FAFSA,
								FOLLOW_UP_CA_DREAM_ACT,
								FOLLOW_UP_TAXES,
								FOLLOW_UP_INCOME_ASSETS,
								FOLLOW_UP_CAL_GRANT_DEADLINE,
								FOLLOW_UP_CAL_GRANT_REQUIREMENTS,
								FOLLOW_UP_OTHER,
								FOLLOW_UP_NOTES,
								FIRST_NAME,
								LAST_NAME,
								ADDRESS,
								CITY,
								ZIP_CODE,
								PHONE1,
								PHONE2,
								EMAIL,
								DOB,
								SSN_CODE,
								SSN,
								EVALUATION_ID,
								Q1,
								Q2,
								Q3,
								Q4,
								Q5,
								Q6,
								Q7,
								Q8,
								Q9,
								Q9_OTHER,
								Q10,
								Q11,
								Q12,
								Q12_OTHER,
								Q13,
								Q13_OTHER,
								Q14,
								Q14_OTHER,
								Q15,
								Q16,
								Q16_OTHER,
								Q17,
								Q18,
								Q18_OTHER,
								Q19,
								ORGANIZATION_ID,
								ORGANIZATION,
								ORGANIZATION_ADDRESS,
								ORGANIZATION_CITY,
								ORGANIZATION_ZIP_CODE,
								WORKSHOP_ID,
								WORKSHOP_DATE,
								START_TIME,
								END_TIME,
								SITE_ID,
								SITE,
								SITE_TYPE,
								SITE_ADDRESS,
								SITE_CITY,
								SITE_ZIP_CODE,
								COUNTY_ID,
								COUNTY,
								REGION_ID,
								REGION,
								QUERY_DATE";
						} else if (IsUserInRole("Organizer") or IsUserInRole("Site Contact")) {
							error = "Insufficient permission to export exit surveys";
							view = "error";	
						}
					break;
					case "scholarships":
						scholarshipGateway = new assets.calgrants.com.gateway.ScholarshipGateway();
						if (IsUserInRole("Super User") or IsUserInRole("Regional Admin")) {
							data = scholarshipGateway.query(argumentCollection = base.wddxToCFML(client.scholarships.queryParamsWDDX));
							//cols = data.columnlist;
							cols = "SCHOLARSHIP_ID
								,STUDENT_ID
								,CLAIM_ID
								,CLAIM_DATE
								,CLAIM_STATUS
								,COHORT
								,SCHOLARSHIP_TYPE
								,FIRST_NAME
								,LAST_NAME
								,ADDRESS
								,CITY
								,ZIP_CODE
								,DOB
								,GENDER
								,RACE_ETHNICITY
								,EMAIL
								,PHONE1
								,PHONE2
								,GDS_FIRST_NAME
								,GDS_LAST_NAME
								,GDS_ADDRESS
								,GDS_CITY
								,GDS_ZIP_CODE
								,GDS_PHONE
								,GDS_EMAIL
								,GDS_HIGH_SCHOOL
								,GDS_HIGH_SCHOOL_CITY
								,GPA
								,ON_TIME_FAFSA
								,ON_TIME_CAL_DREAM_ACT
								,WEBGRANTS_ACCOUNT
								,GRADUATION_MONTH
								,GRADUATION_YEAR
								,VOLUNTEER
								,AUTHORIZED
								,ENROLLMENT_DATE
								,CLASS_SCHEDULE_DEADLINE
								,ATTENDANCE_LEVEL
								,DEGREE_LEVEL
								,INSTITUTION1_ID
								,INSTITUTION
								,TERM_TYPE
								,ACCREDITED
								,DEGREE_GRANTING
								,PROGRAM_YEAR
								,ORGANIZATION_ID
								,ORGANIZATION
								,WORKSHOP_ID
								,WORKSHOP_DATE
								,SITE_ID
								,SITE
								,SITE_TYPE
								,COUNTY
								,REGION_ID
								,REGION
								,DATE_CREATED";
						} else {
							data = scholarshipGateway.query(organizationIDs = request.authUser.organizationID, Cohort = 6);
							cols = "SCHOLARSHIP_ID
								,STUDENT_ID
								,CLAIM_ID
								,CLAIM_DATE
								,CLAIM_STATUS
								,COHORT
								,SCHOLARSHIP_TYPE
								,FIRST_NAME
								,LAST_NAME
								,ADDRESS
								,CITY
								,ZIP_CODE
								,DOB
								,GENDER
								,RACE_ETHNICITY
								,EMAIL
								,PHONE1
								,PHONE2
								,GDS_FIRST_NAME
								,GDS_LAST_NAME
								,GDS_ADDRESS
								,GDS_CITY
								,GDS_ZIP_CODE
								,GDS_PHONE
								,GDS_EMAIL
								,GDS_HIGH_SCHOOL
								,GDS_HIGH_SCHOOL_CITY
								,GPA
								,ON_TIME_FAFSA
								,ON_TIME_CAL_DREAM_ACT
								,WEBGRANTS_ACCOUNT
								,GRADUATION_MONTH
								,GRADUATION_YEAR
								,VOLUNTEER
								,AUTHORIZED
								,ENROLLMENT_DATE
								,CLASS_SCHEDULE_DEADLINE
								,ATTENDANCE_LEVEL
								,DEGREE_LEVEL
								,INSTITUTION
								,TERM_TYPE
								,ACCREDITED
								,DEGREE_GRANTING
								,PROGRAM_YEAR
								,ORGANIZATION
								,WORKSHOP_ID
								,WORKSHOP_DATE
								,SITE
								,SITE_TYPE
								,COUNTY
								,REGION_ID
								,REGION
								,DATE_CREATED";
						}
					break;
					case "payments":
						paymentGateway = new assets.calgrants.com.gateway.PaymentGateway();
						if (IsUserInRole("Super User") or IsUserInRole("Regional Admin")) {
							data = paymentGateway.query(argumentCollection = base.wddxToCFML(client.payments.queryParamsWDDX));
							cols = data.columnList;
						}
					break;
					case "gdsMatchingData":
						storedProcedureGateway = new assets.calgrants.com.gateway.StoredProcedureGateway();
						if (IsUserInRole("Super User")) {
							data = storedProcedureGateway.getGDSMatchingData(Program_Year = base.getCurrentProgramYear());
							cols = "FIRST NAME,LAST NAME,DOB,HOME PHONE,CITY,SURVEY ENTRY ID,SSN LAST 4";
						}
					break;
					default:
						error = "Collection not found";
						view = "error";
				};
			break;
			case "saveCity":
				cityGateway = new assets.calgrants.com.gateway.CityGateway();
				city = cityGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(city, "assets.calgrants.com.bo.City")) {
					error = city;
					view = "error";
				}
			break;
			case "deleteCity":
				cityGateway = new assets.calgrants.com.gateway.CityGateway();
				result = cityGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "saveCounty":
				countyGateway = new assets.calgrants.com.gateway.CountyGateway();
				county = countyGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(county, "assets.calgrants.com.bo.County")) {
					error = county;
					view = "error";
				}
			break;
			case "deleteCounty":
				countyGateway = new assets.calgrants.com.gateway.CountyGateway();
				result = countyGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "saveEvaluation":
				evaluationGateway = new assets.calgrants.com.gateway.EvaluationGateway();
				evaluation = evaluationGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(evaluation, "assets.calgrants.com.bo.Evaluation")) {
					error = evaluation;
					view = "error";
				}
			break;
			case "deleteEvaluation":
				evaluationGateway = new assets.calgrants.com.gateway.EvaluationGateway();
				result = evaluationGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "saveEvaluationPractice":
				evaluationPracticeGateway = new assets.calgrants.com.gateway.EvaluationPracticeGateway();
				evaluationPractice = evaluationPracticeGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(evaluationPractice, "assets.calgrants.com.bo.EvaluationPractice")) {
					error = evaluationPractice;
					view = "error";
				}
			break;
			case "deleteEvaluationPractice":
				evaluationPracticeGateway = new assets.calgrants.com.gateway.EvaluationPracticeGateway();
				result = evaluationPracticeGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "saveFund":
				// added small group.  split up funds and fundSurveys
				fundGateway = new assets.calgrants.com.gateway.FundGateway();
				if (StructKeyExists(args, "Approved")) {
					if (args.Fund_ID eq 0) {
						if (args.Approved eq 1) {
							args.Approved_By_ID = request.authUser.userID;
							args.Approved_Date = Now();
						}
					} else if (args.Fund_ID gt 0) {
						if (args.Approved eq 1) {
							currentFund = fundGateway.get(Fund_ID = args.Fund_ID);
							if (currentFund.getApproved() eq 0) {
								args.Approved_By_ID = request.authUser.userID;
								args.Approved_Date = Now();
							}
						} else if (args.Approved eq 0) {
							args.Approved_By_ID = 0;
							args.Approved_Date = "";
						}
					}
				};
				// save Fund
				fund = fundGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(fund, "assets.calgrants.com.bo.Fund")) {
					error = fund;
					view = "error";
				} else {
					// save Fund_Survey_20##
					args.Fund_ID = fund.getFund_ID();
					args.Submitted_By_ID = fund.getRequested_By_ID();
					
					// ************************* to do: this needs to be swapped out with maintenance free
					fundSurveyGateway = new assets.calgrants.com.gateway.FundSurvey2015Gateway();
					fundSurvey = fundSurveyGateway.save(argumentCollection = args);
					if (NOT IsInstanceOf(fundSurvey, "assets.calgrants.com.bo.FundSurvey2015")) {
						error = fundSurvey;
						view = "error";	
					} else {
						// save Fund_Workshop (for each)
						if (StructKeyExists(args, "Workshop_ID")) {
							fundWorkshopGateway = new assets.calgrants.com.gateway.FundWorkshopGateway();
							for (i = 1; i lte ListLen(args.Workshop_ID); i = i + 1) {
								fundWorkshopArgs = StructNew();
								fundWorkshopArgs.Fund_Workshop_ID = ListGetAt(args.Fund_Workshop_ID, i);
								fundWorkshopArgs.Fund_ID = fund.getFund_ID();
								fundWorkshopArgs.Workshop_ID = ListGetAt(args.Workshop_ID, i);
								if (StructKeyExists(args, "Student_Count_#fundWorkshopArgs.Workshop_ID#")) {
									fundWorkshopArgs.Student_Count = args["Student_Count_#fundWorkshopArgs.Workshop_ID#"];
								}
								if (StructKeyExists(args, "Parent_Count_#fundWorkshopArgs.Workshop_ID#")) {
									fundWorkshopArgs.Parent_Count = args["Parent_Count_#fundWorkshopArgs.Workshop_ID#"];
								}
								if (StructKeyExists(args, "Volunteer_Count_#fundWorkshopArgs.Workshop_ID#")) {
									fundWorkshopArgs.Volunteer_Count = args["Volunteer_Count_#fundWorkshopArgs.Workshop_ID#"];
								}
								if (StructKeyExists(args, "Computer_Count_#fundWorkshopArgs.Workshop_ID#")) {
									fundWorkshopArgs.Computer_Count = args["Computer_Count_#fundWorkshopArgs.Workshop_ID#"];
								}
								if (StructKeyExists(args, "Fund_Amount_#fundWorkshopArgs.Workshop_ID#")) {
									fundWorkshopArgs.Fund_Amount = args["Fund_Amount_#fundWorkshopArgs.Workshop_ID#"];
								}
								if (StructKeyExists(args, "Financial_Aid_Presentation_#fundWorkshopArgs.Workshop_ID#")) {
									fundWorkshopArgs.Financial_Aid_Presentation = args["Financial_Aid_Presentation_#fundWorkshopArgs.Workshop_ID#"];
								}
								if (StructKeyExists(args, "FAFSA_On_The_Web_#fundWorkshopArgs.Workshop_ID#")) {
									fundWorkshopArgs.FAFSA_On_The_Web = args["FAFSA_On_The_Web_#fundWorkshopArgs.Workshop_ID#"];
								}
								if (StructKeyExists(args, "Online_#fundWorkshopArgs.Workshop_ID#")) {
									fundWorkshopArgs.Online = args["Online_#fundWorkshopArgs.Workshop_ID#"];
								}
								if (StructKeyExists(args, "Small_Group_#fundWorkshopArgs.Workshop_ID#")) {
									fundWorkshopArgs.Small_Group = args["Small_Group_#fundWorkshopArgs.Workshop_ID#"];
								}
								if (StructKeyExists(args, "AB540_#fundWorkshopArgs.Workshop_ID#")) {
									fundWorkshopArgs.AB540 = args["AB540_#fundWorkshopArgs.Workshop_ID#"];
								}
								fundWorkshop = fundWorkshopGateway.save(argumentCollection = fundWorkshopArgs);
								if (NOT IsInstanceOf(fundWorkshop, "assets.calgrants.com.bo.FundWorkshop")) {
									error = fundWorkshop;
									view = "error";	
									break;
								}
							}
						}
						if (StructKeyExists(args, "invoiceButton")) {
							Fund_ID = fund.getFund_ID();
							generateFundInvoice = true;
						}
					}
				}
			break;
			case "deleteFund":
				fundGateway = new assets.calgrants.com.gateway.FundGateway();
				result = fundGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "saveFundWorkshop":
				fundWorkshopGateway = new assets.calgrants.com.gateway.FundWorkshopGateway();
				fundWorkshop = fundWorkshopGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(fundWorkshop, "assets.calgrants.com.bo.FundWorkshop")) {
					error = fundWorkshop;
					view = "error";
				}
			break;
			case "deleteFundWorkshop":
				fundWorkshopGateway = new assets.calgrants.com.gateway.FundWorkshopGateway();
				result = fundWorkshopGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "saveFundWorkshopAppeal":
				fundWorkshopGateway = new assets.calgrants.com.gateway.FundWorkshopGateway();
				fundWorkshopAppeal = fundWorkshopGateway.saveAppeal(argumentCollection = args);
				/*if (NOT IsInstanceOf(fundWorkshop, "assets.calgrants.com.bo.FundWorkshop")) {
					error = fundWorkshop;
					view = "error";
				}*/
			break;
			case "saveFundSurvey":
				fundSurveyGateway = new assets.calgrants.com.gateway.FundSurvey2015Gateway();
				fundSurvey = fundSurveyGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(fundSurvey, "assets.calgrants.com.bo.FundSurvey2015")) {
					error = fundSurvey;
					view = "error";	
				}
			break;
			case "saveGDS":
				gdsGateway = new assets.calgrants.com.gateway.GDSGateway();
				gds = gdsGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(gds, "assets.calgrants.com.bo.GDS")) {
					error = gds;
					view = "error";
				}
			break;
			case "deleteGDS":
				gdsGateway = new assets.calgrants.com.gateway.GDSGateway();
				result = gdsGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "saveHighSchool":
				highSchoolGateway = new assets.calgrants.com.gateway.HighSchoolGateway();
				highSchool = highSchoolGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(highSchool, "assets.calgrants.com.bo.HighSchool")) {
					error = highSchool;
					view = "error";
				}
			break;
			case "deleteHighSchool":
				highSchoolGateway = new assets.calgrants.com.gateway.HighSchoolGateway();
				result = highSchoolGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "saveInstitution":
				institutionGateway = new assets.calgrants.com.gateway.InstitutionGateway();
				if (args.Status eq "a") {
					args.Approved = 1;
					args.Disqualified = 0;
				} else if (args.Status eq "d") {
					args.Approved = 0;
					args.Disqualified = 1;
				} else {
					args.Approved = 0;
					args.Disqualified = 0;
				};
				institution = institutionGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(institution, "assets.calgrants.com.bo.Institution")) {
					error = institution;
					view = "error";
				}
			break;
			case "deleteInstitution":
				institutionGateway = new assets.calgrants.com.gateway.InstitutionGateway();
				result = institutionGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "saveOAP":
				oapGateway = new assets.calgrants.com.gateway.OAPGateway();
				oap = oapGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(oap, "assets.calgrants.com.bo.OAP")) {
					error = oap;
					view = "error";
				}
				if (args.OAP_ID eq 0) {
					view = "editOrganizationUsersSites";
				}
			break;
			case "deleteOAP":
				oapGateway = new assets.calgrants.com.gateway.OAPGateway();
				result = oapGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "saveOAPValue":
				oapValueGateway = new assets.calgrants.com.gateway.OAPValueGateway();
				oapValue = oapValueGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(oapValue, "assets.calgrants.com.bo.OAPValue")) {
					error = oapValue;
					view = "error";
				}
			break;
			case "deleteOAPValue":
				oapValueGateway = new assets.calgrants.com.gateway.OAPValueGateway();
				result = oapValueGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "saveCSACOrder":
				workshopGateway = new assets.calgrants.com.gateway.WorkshopGateway();
				for (i=1; i <= ListLen(args.Workshop_ID); i++) {
					wArgs = StructNew();
					wArgs.Workshop_ID = ListGetAt(args.Workshop_ID, i);
					wArgs.Anticipated_Students = args["Anticipated_Students_" & wArgs.Workshop_ID];
					wArgs.Anticipated_Volunteers = args["Anticipated_Volunteers_" & wArgs.Workshop_ID];
					wArgs.Anticipated_Computers = args["Anticipated_Computers_" & wArgs.Workshop_ID];
					workshop = workshopGateway.save(argumentCollection = wArgs);
				}
				csacOrderGateway = new assets.calgrants.com.gateway.CSACOrderGateway();
				csacOrder = csacOrderGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(csacOrder, "assets.calgrants.com.bo.CSACOrder")) {
					error = csacOrder;
					view = "error";
				}
			break;
			case "deleteOrder":
				//orderGateway = new assets.calgrants.com.gateway.OrderGateway();
				csacOrderGateway = new assets.csac.com.gateway.OrderGateway();
				result = csacOrderGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "saveOrganization":
				organizationGateway = new assets.calgrants.com.gateway.OrganizationGateway();
				organization = organizationGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(organization, "assets.calgrants.com.bo.Organization")) {
					error = organization;
					view = "error";
				}
			break;
			case "archiveOrganization":
				organizationGateway = new assets.calgrants.com.gateway.OrganizationGateway();
				organization = organizationGateway.save(Organization_ID = args.Organization_ID, Archived = 1);
				if (NOT IsInstanceOf(organization, "assets.calgrants.com.bo.Organization")) {
					error = organization;
					view = "error";
				}
			break;
			case "unarchiveOrganization":
				organizationGateway = new assets.calgrants.com.gateway.OrganizationGateway();
				organization = organizationGateway.save(Organization_ID = args.Organization_ID, Archived = 0);
				if (NOT IsInstanceOf(organization, "assets.calgrants.com.bo.Organization")) {
					error = organization;
					view = "error";
				}
			break;
			case "deleteOrganization":
				organizationGateway = new assets.calgrants.com.gateway.PAGateway();
				result = organizationGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}	
			break;
			case "savePA":
				paGateway = new assets.calgrants.com.gateway.PAGateway();
				pa = paGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(pa, "assets.calgrants.com.bo.PA")) {
					error = pa;
					view = "error";
				}
			break;
			case "deletePA":
				paGateway = new assets.calgrants.com.gateway.PAGateway();
				result = paGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;	
			case "savePayment":
				if (NOT IsDefined("args.Opt_Out")) {
					args.Opt_Out = 0;
					args.Opt_Out_Reason = "";
				} else {
					args.Approved_Date = "";
					args.Payment_Submitted_Date = "";
					args.Payment_Date = "";
					args.Payment_Type = "";
					args.Payment_Amount = 0;
					args.Payment_Reference = "";
				}
				paymentGateway = new assets.calgrants.com.gateway.PaymentGateway();
				prePayment = paymentGateway.get(Payment_ID = args.Payment_ID);
				payment = paymentGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(payment, "assets.calgrants.com.bo.Payment")) {
					error = payment;
					view = "error";
				} else {
					// send emails
					if (NOT IsDate(prePayment.getInstitution1_Document_Date()) and IsDate(payment.getInstitution1_Document_Date())) {
						base.emailPaymentDocumented(Payment_ID = payment.getPayment_ID());
					} else if (NOT IsDate(prePayment.getApproval_Date()) and IsDate(payment.getApproval_Date())) {
						base.emailPaymentApproved(Payment_ID = payment.getPayment_ID());
					} else if (NOT IsDate(prePayment.getPayment_Date()) and IsDate(payment.getPayment_Date())) {
						base.emailPaymentPaid(Payment_ID = payment.getPayment_ID());
					}
					if (StructKeyExists(args, "receiptButton")) {
						Payment_ID = payment.getPayment_ID();
						generatePaymentReceipt = true;
					}
				}
			break;
			case "deletePayment":
				paymentGateway = new assets.calgrants.com.gateway.PaymentGateway();
				result = paymentGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(payment)) {
					error = result;
					view = "error";
				}
			break;
			case "savePaymentSchedule":
				paymentScheduleGateway = new assets.calgrants.com.gateway.PaymentScheduleGateway();
				paymentSchedule = paymentScheduleGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(paymentSchedule, "assets.calgrants.com.bo.PaymentSchedule")) {
					error = paymentSchedule;
					view = "error";
				}
			break;
			case "deletePaymentSchedule":
				paymentScheduleGateway = new assets.calgrants.com.gateway.PaymentScheduleGateway();
				result = paymentScheduleGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "saveScholarship":
				scholarshipGateway = new assets.calgrants.com.gateway.ScholarshipGateway();
				scholarship = scholarshipGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(scholarship, "assets.calgrants.com.bo.Scholarship")) {
					error = scholarship;
					view = "error";
				}
			break;
			case "deleteScholarship":
				scholarshipGateway = new assets.calgrants.com.gateway.ScholarshipGateway();
				result = scholarshipGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "saveSite":
				siteGateway = new assets.calgrants.com.gateway.SiteGateway();
				site = siteGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(site, "assets.calgrants.com.bo.Site")) {
					error = site;
					view = "error";
				}
			break;
			case "deleteSite":
				siteGateway = new assets.calgrants.com.gateway.SiteGateway();
				result = siteGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "saveStudent":
				/*
				if (NOT IsDefined("args.Follow_Up_FAFSA")) {
					args.Follow_Up_FAFSA = 0;
				}
				if (NOT IsDefined("args.Follow_Up_CA_Dream_Act")) {
					args.Follow_Up_CA_Dream_Act = 0;
				}
				if (NOT IsDefined("args.Follow_Up_Taxes")) {
					args.Follow_Up_Taxes = 0;
				}
				if (NOT IsDefined("args.Follow_Up_Income_Assets")) {
					args.Follow_Up_Income_Assets = 0;
				}
				if (NOT IsDefined("args.Follow_Up_Cal_Grant_Deadline")) {
					args.Follow_Up_Cal_Grant_Deadline = 0;
				}
				if (NOT IsDefined("args.Follow_Up_Cal_Grant_Requirements")) {
					args.Follow_Up_Cal_Grant_Requirements = 0;
				}
				*/
				studentGateway = new assets.calgrants.com.gateway.StudentGateway();
				student = studentGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(student, "assets.calgrants.com.bo.Student")) {
					error = student;
					view = "error";
				}
			break;
			case "deleteStudent":
				studentGateway = new assets.calgrants.com.gateway.StudentGateway();
				result = studentGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "saveStudentPractice":
				studentPracticeGateway = new assets.calgrants.com.gateway.StudentPracticeGateway();
				studentPractice = studentPracticeGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(studentPractice, "assets.calgrants.com.bo.StudentPractice")) {
					error = studentPractice;
					view = "error";
				}
			break;
			case "deleteStudentPractice":
				studentPracticeGateway = new assets.calgrants.com.gateway.StudentPracticeGateway();
				result = studentPracticeGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "saveUser":
				userGateway = new assets.calgrants.com.gateway.UserGateway();
				user = userGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(user, "assets.calgrants.com.bo.User")) {
					error = user;
					view = "error";
				}
			break;
			case "archiveUser":
				userGateway = new assets.calgrants.com.gateway.UserGateway();
				user = userGateway.save(User_ID = args.User_ID, Archived = 1);
				if (NOT IsInstanceOf(user, "assets.calgrants.com.bo.User")) {
					error = user;
					view = "error";
				}
			break;
			case "unarchiveUser":
				userGateway = new assets.calgrants.com.gateway.UserGateway();
				user = userGateway.save(User_ID = args.User_ID, Archived = 0);
				if (NOT IsInstanceOf(user, "assets.calgrants.com.bo.User")) {
					error = user;
					view = "error";
				}
			break;
			case "deleteUser":
				userGateway = new assets.calgrants.com.gateway.UserGateway();
				result = userGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "saveVolunteer":
				if (NOT IsDefined("args.Student")) {
					args.Student = 0;
				}
				if (NOT IsDefined("args.Financial_Aid_Expert")) {
					args.Financial_Aid_Expert = 0;
				}
				if (NOT IsDefined("args.FAFSA_Expert")) {
					args.FAFSA_Expert = 0;
				}
				if (NOT IsDefined("args.AB540_Expert")) {
					args.AB540_Expert = 0;
				}
				if (NOT IsDefined("args.Finance_Expert")) {
					args.Finance_Expert = 0;
				}
				if (NOT IsDefined("args.Tax_Expert")) {
					args.Tax_Expert = 0;
				}
				if (NOT IsDefined("args.Outreach_Expert")) {
					args.Outreach_Expert = 0;
				}
				if (NOT IsDefined("args.Technology_Expert")) {
					args.Technology_Expert = 0;
				}
				if (NOT IsDefined("args.Translator")) {
					args.Translator = 0;
				}
				volunteerGateway = new assets.calgrants.com.gateway.VolunteerGateway();
				volunteer = volunteerGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(volunteer, "assets.calgrants.com.bo.Volunteer")) {
					error = volunteer;
					view = "error";
				} else {
					if (IsDefined("args.Workshop_Volunteer_IDs") AND IsDefined("args.Workshop_IDs") AND IsDefined("args.Workshop_Statuses")) {
						workshopVolunteerGateway = new assets.calgrants.com.gateway.WorkshopVolunteerGateway();
						for (i = 1; i lte listlen(args.Workshop_Volunteer_IDs); i = i + 1) {
							if (ListGetAt(args.Workshop_Statuses, i) neq "Unassigned") {
								wvArgs = StructNew();
								wvArgs.Workshop_Volunteer_ID = ListGetAt(args.Workshop_Volunteer_IDs, i);
								wvArgs.Deleted = 0;
								wvArgs.Workshop_ID = ListGetAt(args.Workshop_IDs, i);
								wvArgs.Volunteer_ID = volunteer.getVolunteer_ID();
								wvArgs.Status = ListGetAt(args.Workshop_Statuses, i);
								workshopVolunteer = workshopVolunteerGateway.save(argumentCollection = wvArgs);
								if (NOT IsInstanceOf(workshopVolunteer, "assets.calgrants.com.bo.WorkshopVolunteer")) {
									error = workshopVolunteer;
									view = "error";
									break;
								}
							} else if (ListGetAt(args.Workshop_Volunteer_IDs, i) gt 0) {
								wvArgs = StructNew();
								wvArgs.Workshop_Volunteer_ID = ListGetAt(args.Workshop_Volunteer_IDs, i);
								wvArgs.Deleted = 1;
								wvArgs.Workshop_ID = ListGetAt(args.Workshop_IDs, i);
								wvArgs.Volunteer_ID = volunteer.getVolunteer_ID();
								wvArgs.Status = "Unassigned";
								workshopVolunteer = workshopVolunteerGateway.save(argumentCollection = wvArgs);
								if (NOT IsInstanceOf(workshopVolunteer, "assets.calgrants.com.bo.WorkshopVolunteer")) {
									error = workshopVolunteer;
									view = "error";
									break;
								}
							}
							
						}
					}
				}
			break;
			case "deleteVolunteer":
				volunteerGateway = new assets.calgrants.com.gateway.VolunteerGateway();
				result = volunteerGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "saveVolunteerCity":
				volunteerCityGateway = new assets.calgrants.com.gateway.VolunteerCityGateway();
				volunteerCity = volunteerCityGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(volunteerCity, "assets.calgrants.com.bo.VolunteerCity")) {
					error = volunteerCity;
					view = "error";
				}
			break;
			case "deleteVolunteerCity":
				volunteerCityGateway = new assets.calgrants.com.gateway.VolunteerCityGateway();
				result = volunteerCityGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "saveWorkshop":
				if (NOT IsDefined("args.Online")) {
					args.Online = 0;
				}
				if (NOT IsDefined("args.FAFSA_On_The_Web")) {
					args.FAFSA_On_The_Web = 0;
				}
				if (NOT IsDefined("args.Financial_Aid_Presentation")) {
					args.Financial_Aid_Presentation = 0;
				}
				if (NOT IsDefined("args.Small_Group")) {
					args.Small_Group = 0;
				}
				if (NOT IsDefined("args.AB540")) {
					args.AB540 = 0;
				}
				if (NOT IsDefined("args.Alt_Language_Workshop")) {
					args.Alt_Language_Workshop = 0;
				}
				if (NOT IsDefined("args.Translators")) {
					args.Translators = 0;
				}
				if (NOT IsDefined("args.Tax_Assistance")) {
					args.Tax_Assistance = 0;
				}
				if (NOT IsDefined("args.Foster_Youth")) {
					args.Foster_Youth = 0;
				}
				if (NOT IsDefined("args.Refreshments")) {
					args.Refreshments = 0;
				}
				if (NOT IsDefined("args.Child_Care")) {
					args.Child_Care = 0;
				}
				if (NOT IsDefined("args.Other_Services")) {
					args.Other_Services = 0;
				}
				args.Workshop_Date = DateFormat(args.Workshop_Date, "m/d/yyyy");
				args.Start_Time = TimeFormat(args.Start_Time, "HH:mm");
				args.End_Time = TimeFormat(args.End_Time, "HH:mm");
				workshopGateway = new assets.calgrants.com.gateway.WorkshopGateway();
				workshop = workshopGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(workshop, "assets.calgrants.com.bo.Workshop")) {
					error = workshop;
					view = "error";
				}
			break;
			case "deleteWorkshop":
				workshopGateway = new assets.calgrants.com.gateway.WorkshopGateway();
				result = workshopGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "saveWorkshopVolunteer":
				workshopVolunteerGateway = new assets.calgrants.com.gateway.WorkshopVolunteerGateway();
				workshopVolunteer = workshopVolunteerGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(workshopVolunteer, "assets.calgrants.com.bo.WorkshopVolunteer")) {
					error = workshopVolunteer;
					view = "error";
				}
			break;
			case "deleteWorkshopVolunteer":
				workshopVolunteerGateway = new assets.calgrants.com.gateway.WorkshopVolunteerGateway();
				result = workshopVolunteerGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "updateWorkshopVolunteerStatus":
				workshopVolunteerGateway = new assets.calgrants.com.gateway.WorkshopVolunteerGateway();
				if (args.Status eq "Unassigned") {
					args.Deleted = 1;
				}
				workshopVolunteer = workshopVolunteerGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(workshopVolunteer, "assets.calgrants.com.bo.WorkshopVolunteer")) {
					error = workshopVolunteer;
					view = "error";
				}
			break;
			case "saveZipCode":
				zipCodeGateway = new assets.calgrants.com.gateway.ZipCodeGateway();
				zipCode = zipCodeGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(zipCode, "assets.calgrants.com.bo.ZipCode")) {
					error = zipCode;
					view = "error";
				}
			break;
			case "deleteZipCode":
				zipCodeGateway = new assets.calgrants.com.gateway.ZipCodeGateway();
				result = zipCodeGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "emailScholarPassword":
				emailSent = base.emailScholarPassword(Email = args.Email);
				if (emailSent) {
					ArrayAppend(request.alerts, "Your password has been sent to #args.Email#");
					view = "login";
				} else {
					ArrayAppend(request.alerts, "There was a problem sending your password to #args.Email#");
					view = "login";
				}
			break;			
			case "saveScholar":
				if (IsUserLoggedIn() and (IsUserInRole("Scholar") or IsUserInRole("Claimant"))) {
					//args.Scholarship_ID = GetAuthUser();
					scholarshipGateway = new assets.calgrants.com.gateway.ScholarshipGateway();
					scholarship = scholarshipGateway.get(Scholarship_ID = GetAuthUser());
				/***
				} else if (StructKeyExists(args, "Claim_ID") and Len(Trim(args.Claim_ID)) gt 0) {
					cScholar = scholarshipGateway.query(Claim_ID = args.Claim_ID, Deleted = "");
					qScholar = scholarshipGateway.query(Student_ID = cScholar.Student_ID, Deleted = 0);
					args.Scholarship_ID = qScholar.Scholarship_ID;
				***/
				} else {
					error = "saveScholar is limited to authenticated or claiming scholars. GetAuthUser or Claim_ID is required.";
					view = "error";
					break;
				}
				if (StructKeyExists(args, "New_High_School_ID") and args.New_High_School_ID eq 0) {
					newHighSchool = StructNew();
					newHighSchool.High_School_ID = 0;
					newHighSchool.High_School = Trim(New_High_School);
					newHighSchool.City = Trim(New_High_School_City);
					newHighSchool.CEEB_ID = "";
					highSchoolGateway = new assets.calgrants.com.gateway.HighSchoolGateway();
					highSchool = highSchoolGateway.save(argumentCollection = newHighSchool);
					if (NOT IsInstanceOf(highSchool, "assets.calgrants.com.bo.HighSchool")) {
						error = highSchool;
						view = "error";
						break;
					} else {
						args.High_School_ID = highSchool.getHigh_School_ID();
					}
				}
				if (StructKeyExists(args, "High_School_ID") and args.High_School_ID gt 0) {
					args.High_School = "";	
				}
				if (StructKeyExists(args, "Payment_Method")) {
					if (args.Payment_Method neq "EFT") {
						args.Account_Type = "";
						args.Routing_Number = "";
						args.Account_Number = "";
					}
				}
				if (StructKeyExists(args, "New_Institution1") and args.New_Institution1 eq true) {
					newInstitution1 = StructNew();
					newInstitution1.Institution_ID = 0;
					newInstitution1.Institution = Institution1_Institution;
					newInstitution1.FAO_Address1 = Institution1_FAO_Address1;
					newInstitution1.FAO_City = Institution1_FAO_City;
					newInstitution1.FAO_State = Institution1_FAO_State;
					newInstitution1.FAO_Zip_Code = Institution1_FAO_Zip_Code;
					newInstitution1.FAO_Phone = Institution1_FAO_Phone;
					institutionGateway = new assets.calgrants.com.gateway.InstitutionGateway();
					institution1 = institutionGateway.save(argumentCollection = newInstitution1);
					if (NOT IsInstanceOf(institution1, "assets.calgrants.com.bo.Institution")) {
						error = institution1;
						view = "error";
						break;
					} else {
						args.Institution1_ID = institution1.getInstitution_ID();
					}
				}
				if (StructKeyExists(args, "New_Institution2") and args.New_Institution2 eq true) {
					newInstitution2 = StructNew();
					newInstitution2.Institution_ID = 0;
					newInstitution2.Institution = Institution2_Institution;
					newInstitution2.FAO_Address1 = Institution2_FAO_Address1;
					newInstitution2.FAO_City = Institution2_FAO_City;
					newInstitution2.FAO_State = Institution2_FAO_State;
					newInstitution2.FAO_Zip_Code = Institution2_FAO_Zip_Code;
					newInstitution2.FAO_Phone = Institution2_FAO_Phone;
					if (NOT IsDefined("institutionGateway")) {
						institutionGateway = new assets.calgrants.com.gateway.InstitutionGateway();
					}
					institution2 = institutionGateway.save(argumentCollection = newInstitution2);
					if (NOT IsInstanceOf(institution2, "assets.calgrants.com.bo.Institution")) {
						error = institution2;
						view = "error";
						break;
					} else {
						args.Institution2_ID = institution2.getInstitution_ID();
					}
				}
				// mark the scholarship as claimed when the user passes in the Authorized param for an unclaimed scholarship
				if (StructKeyExists(args, "Authorized")) {
					if ((scholarship.getScholarship_Type() eq "performance based scholarship" and scholarship.getCohort() eq 5 and args.Authorized eq 0) OR (scholarship.getCohort() eq 7 and args.Authorized eq 0)) {
						args.Authorized_By = "";
						view = "scholarUnclaimed";
					} else {
						args.Claim_Date = Now();
						emailResult = base.emailScholarshipClaimed(Scholarship_ID = args.Scholarship_ID);
					}
				}
				scholar = scholarshipGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(scholar, "assets.calgrants.com.bo.Scholarship")) {
					error = scholar;
					view = "error";
				}
			break;
			/*******************************
			retired actions
			case "verifyClaim":
				scholarshipGateway = new assets.calgrants.com.gateway.ScholarshipGateway();
				cScholarship = scholarshipGateway.query(Claim_ID = args.Claim_ID, Deleted = "");
				qScholarship = scholarshipGateway.query(Student_ID = cScholarship.Student_ID, Deleted = 0);
				// failed claim
				if (qScholarship.RecordCount eq 0) {
					ArrayAppend(request.alerts, "Invalid Claim ID.\n\nVerify that you have correctly entered the Claim ID from your scholarship award letter.\n\nIf you continue to get this message, contact #request.personality.name# at #request.personality.email#.");
					view = "login";
				// duplicate Claim IDs
				} else if (qScholarship.RecordCount gt 1) {
					ArrayAppend(request.alerts, "There was a problem validating the scholarship associated with Claim ID \""" & args.Claim_ID & "\"".\n\nIf you continue to get this message, contact #request.personality.name# at #request.personality.email#.");
					view = "login";
				// valid Claim ID
				} else {
					storedProcedureGateway = new assets.calgrants.com.gateway.StoredProcedureGateway();
					currentCohort = storedProcedureGateway.call("getCurrentCohort");
					scholarship = scholarshipGateway.get(Scholarship_ID = qScholarship.Scholarship_ID);
					// already claimed, should login instead
					if (IsDate(qScholarship.Claim_Date)) {
						ArrayAppend(request.alerts, "The scholarship associated with Claim ID \""" & args.Claim_ID & "\"" has been claimed.\n\nLogin with the email address and password you created when you claimed your scholarship.\n\nIf you do not remember your password, select \""Forgot your password\?\"" below to retrieve your password.");
						view = "login";
					// scholarship expired unclaimed
					} else if (qScholarship.Cohort lt currentCohort.currentCohort) {
						ArrayAppend(request.alerts, "The scholarship claiming deadline has passed.\n\nContact #request.personality.name# at #request.personality.email# with questions.");
						view = "login";
					// Claim ID valid, begin claim process
					} else {
						view = "scholarWelcome";
					}
				}
			break;
			case "saveOrderValue":
				orderValueGateway = new assets.calgrants.com.gateway.OrderValueGateway();
				orderValue = orderValueGateway.save(argumentCollection = args);
				if (NOT IsInstanceOf(orderValue, "assets.calgrants.com.bo.OrderValue")) {
					error = orderValue;
					view = "error";
				}
			break;
			case "deleteOrderValue":
				orderValueGateway = new assets.calgrants.com.gateway.OrderValueGateway();
				result = orderValueGateway.delete(argumentCollection = args);
				if (NOT IsBoolean(result)) {
					error = result;
					view = "error";
				}
			break;
			case "saveAccount":
				if (args.Organization_ID eq 0) {
					args.Approved = 0;
					organizationGateway = new assets.calgrants.com.gateway.OrganizationGateway();
					organization = organizationGateway.save(argumentCollection = args);
					if (NOT IsInstanceOf(organization, "assets.calgrants.org.bo.Organization")) {
						error = organization;
						view = "error";
					} else {
						// use the wddxToCFML to unpack the user wddx packet
						// base = new assets.calgrants.com.Base();
						userArgs = base.wddxToCFML(args.userWDDX);
						userArgs.Approved = 1;
						userArgs.Role = "Organizer";
						userArgs.Organization_ID = organization.getOrganization_ID();
						userGateway = new assets.calgrants.com.gateway.UserGateway();
						user = userGateway.save(argumentCollection = userArgs)
						if (NOT IsInstanceOf(user, "assets.calgrants.com.bo.User")) {
							// delete the new organization so it doesn't get recreated
							organizationGateway.detroy(Organization_ID = organization.getOrganization_ID());
							error = user;
							view = "error";
						}
					}
				} else {
					// base = new assets.calgrants.com.Base();
					userArgs = base.wddxToCFML(args.userWDDX);
					userArgs.Approved = 0;
					userArgs.Role = "Site Contact";
					userArgs.Organization_ID = args.Organization_ID;
					userGateway = new assets.calgrants.com.gateway.UserGateway();
					user = userGateway.save(argumentCollection = userArgs)
					if (NOT IsInstanceOf(user, "assets.calgrants.com.bo.User")) {
						error = user;
						view = "error";
					}
				}					
			break;
			case "emailPassword":
				// base = new assets.calgrants.com.Base();
				result = base.emailPassword(argumentCollection = args);
				if (NOT result)	{
					error = "There was a problem sending your password.  Please check your e-mail address and try again.";
					view = "error";
				}
			break;
			*******************************/
			default:
				error = "Action not found";
				view = "error";
		}
	}
</cfscript>
<cfif action eq "import" and IsDefined("uploadFile") and FileExists(uploadFile)>
	<cfspreadsheet action="read" src="#uploadFile#" query="importData" headerrow="1" excludeheaderrow="true">
	<cfdump var="#importData.columnlist#">
	<cfabort>
	<!--- follow up, volunteers, GDS matcing data, etc --->
<cfelseif action eq "export" and IsDefined("exportFormat") and IsDefined("collection") and IsDefined("data") and IsQuery(data)>
	<cfif NOT DirectoryExists(request.tempDirectory)>
		<cfdirectory directory="#request.tempDirectory#" action="create" />
	</cfif>
	<!--- Get a list of export files in the application temp directory --->
	<cfdirectory action="list" directory="#request.tempDirectory#" name="tempFiles" />
	<cfloop query="tempFiles">
		<!--- Delete files more than a day old --->
		<cfif DateLastModified lt DateAdd("d", -1, Now())>
			<cffile action="delete" file="#Directory#\#Name#">
		</cfif>
	</cfloop>
	<cfset exportFilename = "#collection#_#DateFormat(now(), 'yyyy-mm-dd')#-#TimeFormat(now(), 'HH-mm-ss-L')#.#exportFormat#" />
	<cfswitch expression="#exportFormat#">
		<cfcase value="csv">
			<!--- Output as content stream which will trigger a download --->
			<cfheader name="Content-Disposition" value="attachment; filename=#exportFilename#">
			<cfcontent type="text/csv">
			<cfoutput>#base.queryToCSV(data, cols, true, ",")#</cfoutput>
			<cfabort>
		</cfcase>
		<cfcase value="xls">
			<!--- Generate Excel file in application temp directory --->
			<cfspreadsheet action="write" filename="#request.tempDirectory##exportFilename#" overwrite="true" query="data" sheetname="#collection#">
			<!--- Relocate to the generated file for download --->
			<cflocation url="#request.pathToTemp##exportFilename#" addtoken="no">
		</cfcase>
	</cfswitch>
</cfif>
